#include<cstdio>
#include<cstring>
int n,k,c=0,ans=-1,bi=0;
int a[51],b[51];
bool conf[101],small[101],big[101],find=false;
int main()
{
	freopen("test.in","r",stdin);
	scanf("%d%d",&n,&k);
	memset(conf,false,sizeof(conf));
	memset(small,false,sizeof(small));
	memset(big,false,sizeof(big));
	for(int i=1;i<=k;i++)
	{
		int t;
		scanf("%d",&t);
		for(int j=1;j<=t;j++)
			scanf("%d",&a[j]);
		for(int j=1;j<=t;j++)
			scanf("%d",&b[j]);
		char op;
		scanf("%c%c",&op,&op);
		if(op=='=')
		{
			for(int j=1;j<=t;j++)
			{
				if(!conf[a[j]])c++;
				conf[a[j]]=true;
				small[a[j]]=big[a[j]]=false;
				if(!conf[b[j]])c++;
				conf[b[j]]=true;
				small[b[j]]=big[b[j]]=false;
			}
		}
		if(op=='<')
		{
			bool cs=true,cb=true;;
			for(int j=1;j<=t;j++)
			{
				
				if(big[a[j]])
				{c++;conf[a[j]]=true;big[a[j]]=false;}
				if(!conf[a[j]])
				{cs=false;small[a[j]]=true;}
				if(small[b[j]])
				{c++;conf[b[j]]=true;small[b[j]]=false;}
				if(!conf[b[j]])
				{cb=false;big[b[j]]=true;}
			}
			if(cs)ans=0;//>
			if(cb)ans=1;//<
		}
		if(op=='>')
		{
			bool cs=true,cb=true;;
			for(int j=1;j<=t;j++)
			{
				
				if(big[b[j]])
				{c++;conf[b[j]]=true;big[b[j]]=false;}
				if(!conf[b[j]])
				{cb=false;small[b[j]]=true;}
				if(small[a[j]])
				{c++;conf[a[j]]=true;small[a[j]]=false;}
				if(!conf[a[j]])
				{cs=false;big[a[j]]=true;}
			}
			if(cs)ans=0;//>
			if(cb)ans=1;//<
		}
	}
	if(ans==0)
	{
		int p,pp;
		for(int i=1;i<=n;i++)
			if(big[i]){p++;pp=i;}
		if(p==1){printf("%d\n",pp);find=true;}
	}
	if(ans==1)
	{
		int p,pp;
		for(int i=1;i<=n;i++)
			if(small[i]){p++;pp=i;}
		if(p==1){printf("%d\n",pp);find=true;}
	}
	if(!find&&c==n-1)
	{
		for(int i=1;i<=n;i++)
			if(!conf[i]){find=true;printf("%d\n",i);break;}
	}
	if(!find)printf("0\n");
	return 0;
}



				



